/*
 *  Copyright (c) 2022 ZhuHai Jieli Technology Co.,Ltd.
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

#ifndef ADAPTER_THREAD_H
#define ADAPTER_THREAD_H

#include "generic/typedef.h"
#include "generic/list.h"

#define PRIORITY_NUM   4

struct thread_owner {
    struct list_head head;
    int (*create)(void (*fun)(struct thread_owner *), u8);
    int (*delete)(u8);
    int (*suspend)(u8, u8);
    int (*resume)(void);
};

struct thread {
    struct list_head entry;
    struct thread_owner *owner;
    char *name;
    void (*fun)(struct thread *);
    u8 priority;
    // resume
    u8 resume_cnt;
    // suspend
    u8 suspend_timeout;
};

int thread_owner_init(struct thread_owner *owner);

int thread_create(struct thread *th, char *name, void (*fun)(struct thread *), struct thread_owner *owner);

void thread_suspend(struct thread *th, int timeout);

void thread_resume(struct thread *th);

int thread_delete(struct thread *th);

void thread_run(struct thread_owner *owner);

#endif

